package com.csu.controller;

import com.csu.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RedisController {
    @Autowired
    RedisService redisService;

    @GetMapping("/set")
    public String setValue(@RequestParam String key, @RequestParam String value){
        redisService.set(key, value);
        return "value: " + value;
    }

    @GetMapping("/get")
    public String getValue(@RequestParam String key){
        return (String) redisService.get(key);
    }

    @DeleteMapping("/delete")
    public String deleteValue(@RequestParam String key){
        if(!redisService.delete(key)){
            return "删除成功";
        }
        return "删除失败";
    }
}
